#include <bits/stdc++.h>
// 2025/02/05
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int s, n, d, dp[45001], w[10000], v[10000];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> s >> n >> d;
    for (int i = 1; i <= d; i++)
        cin >> w[i] >> v[i], w[i] /= 1000;
    for (int i = 1; i <= d; i++)
        for (int j = w[i]; j <= s / 1000 * 45; j++)
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
    int ans = s;
    for (int i = 1; i <= n; i++)
        ans += dp[ans / 1000];
    cout << ans << endl;
    return 0;
}